from datetime import datetime
from django.db import models


# Create your models here.


# 部门表
class Deportment(models.Model):
    title = models.CharField(max_length=32, verbose_name='部门名称')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'deportment'
        verbose_name_plural = '部门表'

    def __str__(self):
        return self.title


# 岗位表
class Job(models.Model):
    title = models.CharField(max_length=32, verbose_name='岗位名称')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'job'
        verbose_name_plural = '岗位表'

    def __str__(self):
        return self.title


# 职级表
class Rank(models.Model):
    title = models.CharField(max_length=32, verbose_name='职级名称')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'rank'
        verbose_name_plural = '职级表'

    def __str__(self):
        return self.title


# 角色表
class Role(models.Model):
    title = models.CharField(max_length=32, verbose_name='角色名称')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'role'
        verbose_name_plural = '角色表'

    def __str__(self):
        return self.title


# 权限菜单表
class Menus(models.Model):
    title = models.CharField(max_length=32, verbose_name='权限菜单名称')
    menu = models.ForeignKey('self', on_delete=models.CASCADE, null=True)
    url=models.CharField(max_length=100,null=True,verbose_name='菜单路径')
    role = models.ManyToManyField(Role, verbose_name='角色')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'menus'
        verbose_name_plural = '权限菜单表'

    def __str__(self):
        return self.title


# 菜单表
# class MenuModel(models.Model):
#     menu_name = models.CharField(max_length=32, verbose_name='菜单')
#     pmenu = models.ForeignKey('self', on_delete=models.CASCADE, null=True)
#     create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
#     updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
#
#     class Meta:
#         db_table = 'menu'
#         verbose_name_plural = '菜单表'
#
#     def __str__(self):
#         return self.menu_name


# 员工表
class Staff(models.Model):
    name = models.CharField(max_length=32, verbose_name='员工姓名')
    mobile = models.CharField(max_length=11, verbose_name='手机号')
    email = models.EmailField(max_length=32, verbose_name='邮箱')
    password = models.CharField(max_length=128, verbose_name='密码')
    deportment = models.ForeignKey(Deportment, on_delete=models.CASCADE, verbose_name='部门')
    job = models.ForeignKey(Job, on_delete=models.CASCADE, verbose_name='岗位')
    rank = models.ForeignKey(Rank, on_delete=models.CASCADE, verbose_name='职级')
    role = models.ForeignKey(Role, on_delete=models.CASCADE, verbose_name='角色')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    last_time = models.DateTimeField(default=datetime.now, verbose_name='更新时间')

    class Meta:
        db_table = 'staff'
        verbose_name_plural = '员工表'

    def __str__(self):
        return self.name
